<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="../static/js/jquery/jquery-2.1.4.min.js" type="text/javascript"></script>
    <script src="../static/layui/layui.js" type="text/javascript"></script>
    <script src="../static/js/index/index.js" type="text/javascript"></script>
    <script src="../static/js/index/freezeheader.js" type="text/javascript"></script>
    <script src="../static/layui/lay/modules/layer.js" type="text/javascript"></script>
    <script src="../static/js/index/sliders.js" type="text/javascript"></script>
    <script src="../static/js/index/html5.js" type="text/javascript"></script>
    <link rel="stylesheet" href="../static/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="../static/layui/css/modules/layer/default/layer.css"/>
    <link rel="stylesheet" href="../static/css/global.css"/>
    <link rel="stylesheet" href="./css/amazeui.min.css"/>
    <link rel="stylesheet" href="./css/admin.css"/>
    <link rel="stylesheet"
          href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <%--<script type="text/javascript" src="js/jquery-3.4.1.min.js"></script>--%>
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <script
            src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>

    <link rel="stylesheet" type="text/css"
          href="https://www.layuicdn.com/layui/css/layui.css"/>

    <script type="text/javascript" src="js/layer.js"></script>
    <link rel="stylesheet" href="css/layer.css">
</head>

<body>
<div class="admin-content-body">
    <div class="am-cf am-padding am-padding-bottom-0">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">评论管理</strong>
            <small></small>
        </div>
    </div>

    <hr>
    <div class="am-g">
        <div class="am-u-sm-12 am-u-md-4">
            <div class="layui-form-item">
                <div class="layui-input-inline" style="width:65%;">
                    <input type="text" id="keyName" name="keyContent" lay-verify="required" placeholder="请输入关键字"
                           class="layui-input">
                </div>
                <button class="layui-btn" onclick="getMessage();">搜索</button>
            </div>
        </div>
    </div>
    <div class="am-g">
        <div class="am-u-sm-12">
            <form class="am-form">
                <table class="am-table am-table-striped am-table-hover table-main">
                    <thead>
                    <tr>
                        <th class="table-id">评论ID</th>
                        <th class="table-date am-hide-sm-only">评论者</th>

                        <th class="table-author am-hide-sm-only">评论发布时间</th>
                        <th class="table-title">评论内容</th>
                        <th class="table-title">评论的问题ID</th>
                        <th class="table-title">评论者类型</th>
                        <th class="table-set">操作</th>
                    </tr>
                    </thead>
                    <tbody id="commentResult">
                    <c:forEach items="${comments}" var="comment">

                        <tr>
                            <td class="table-type">${comment.commentId}</td>
                            <td class="am-hide-sm-only">${comment.commentReviewName}</td>
                            <td class="am-hide-sm-only"><fmt:formatDate value="${comment.commentTime}"
                                                                        pattern="yyyy-MM-dd HH:mm:ss"/></td>
                            <td class="am-hide-sm-only">${comment.commentContent}</td>
                            <td class="am-hide-sm-only">${comment.questionId}</td>
                            <c:set var="cnt03" scope="session"
                                   value="${comment.commentType}"></c:set>
                            <c:if test="${cnt03==0}">
                                <td class="am-hide-sm-only">学生</td>
                            </c:if>
                            <c:if test="${cnt03==1}">
                                <td class="am-hide-sm-only">老师</td>
                            </c:if>
                            <td>
                                <div class="am-btn-toolbar">
                                    <div class="am-btn-group am-btn-group-xs">
                                        <a class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only"
                                           onclick="delComment(${comment.commentId})">删除</a>
                                    </div>
                                </div>
                            </td>
                        </tr>
                    </c:forEach>
                    </tbody>
                </table>
                <hr>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript">
    var nowdatas;
    var inputName;

    function getMessage() {
        intputName = $("#keyName").val();
        $.ajax({
            type: "get",
            url: "/admin/comment/search",
            data: {
                "keyContent": intputName
            },
            dataType: 'json',
            success: function (data) {
                if (data.length==0) {
                    alert("没有搜索到对应的内容");
                }
                nowdatas = data;
                add();
            }
        })
    }

    function add() {
        $("#commentResult").empty();
        for (var i = 0; i < nowdatas.length; i++) {
            str1 = '<tr><td>' + (i + 1) + '</td><td>' +
                nowdatas[i]['commentReviewName']
                + '</td><td>' +
                nowdatas[i]['commentTime']
                + '</td><td>' +
                nowdatas[i]['commentContent']
                + '</td><td>' +
                nowdatas[i]['questionId']
                + '</td>' +
                '<td>' +
                nowdatas[i]['commentType']
                + '</td><td><div class="am-btn-toolbar"><div class="am-btn-group am-btn-group-xs"><dd></dd><a href="/answer/del/' + nowdatas['answerId'] + '">删除</a></div></div></td>' +
                +'</tr>';
            $("#commentResult").append(str1);
        }
    }

    function delComment(commentId) {
        inputName = commentId;
        $.ajax({
                type: "get",
                url: "/comment/del",
                data: {"commentId": inputName},
                dataType: 'json',
                success: function (data) {
                    //  location.reload();
                    parent.location.reload();
                    alert("删除成功！");
                }
            }
        )
    }
</script>
</body>
</html>